<template>
  <view class="nav-bar" :style="[style]">
    <view class="left" @click="onBack">
      <view class="iconfont icon-31fanhui1"></view>
    </view>
    <view class="title">{{ title }}</view>
    <view class="right"></view>
  </view>
</template>

<script>
export default {
  name: 'NavBar',
  props: {
    title: { type: String, default: '' }
  },
  data() {
    return {
      height: '0rpx',
      top: '0rpx',
    }
  },
  computed: {
    style() {
      return {
        top: this.top,
        height: this.height,
      }
    }
  },
  emits: ['back'],
  methods: {
    onBack() {
      this.$emit('back');
      uni.navigateBack()
    },
  },
  mounted() {
    let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
    this.height = menuButtonInfo.height * 2 + 'rpx';
    this.top = menuButtonInfo.top * 2 + 'rpx';
  }
}
</script>

<style lang="scss" scoped>
.nav-bar {
  position: absolute;
  left: 0;
  width: 100%;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  padding: 0 26rpx;
  z-index: 100;
  box-sizing: border-box;

  .title {
    flex: 1;
    text-align: center;
    color: #fff;
  }

  .left,
  .right {
    display: flex;
    align-items: center;
    width: 60rpx;
    height: 100%;

    .iconfont {
      font-size: 40rpx;
      color: #fff;
    }
  }



}
</style>